//aes 加密解密封装
const { log } = require('console')
const crypto = require('crypto')
// 加密
function encrypt(key,iv,data) {
    // 创建加密
    let dep = crypto.createCipheriv("aes-128-cbc",key,iv)

    return dep.update(data,"binary",'hex') + dep.final("hex")
}

//解密
function decrypt(key,iv,cryted) {

    cryted = Buffer.from(cryted,"hex").toString("binary")
    // 创建解密
    let dep = crypto.createDecipheriv("aes-128-cbc",key,iv)

    return dep.update(cryted,"binary","utf8") + dep.final("utf8")
}


let key = 'abcdef1234567890'
let vi = 'tbcdey1234567890'

// let data = '123456'
// // 加密结果
// let cryted = encrypt(key,vi,data)
// // 解密结果
// let decryted = decrypt(key,vi,cryted)

//导出
module.exports = {decrypt,encrypt,key,vi}